package com.ruoyi.project.erp.attention.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.erp.attention.domain.ErpAttention;
import com.ruoyi.project.erp.attention.service.IErpAttentionService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 提醒Controller
 * 
 * @author ruoyi
 * @date 2021-08-10
 */
@Controller
@RequestMapping("/erp/attention")
public class ErpAttentionController extends BaseController
{
    private String prefix = "erp/attention";

    @Autowired
    private IErpAttentionService erpAttentionService;

    @RequiresPermissions("erp:attention:view")
    @GetMapping()
    public String attention()
    {
        return prefix + "/attention";
    }

    /**
     * 查询提醒列表
     */
    @RequiresPermissions("erp:attention:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ErpAttention erpAttention)
    {
        startPage();
        List<ErpAttention> list = erpAttentionService.selectErpAttentionList(erpAttention);
        return getDataTable(list);
    }

    /**
     * 导出提醒列表
     */
    @RequiresPermissions("erp:attention:export")
    @Log(title = "提醒", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ErpAttention erpAttention)
    {
        List<ErpAttention> list = erpAttentionService.selectErpAttentionList(erpAttention);
        ExcelUtil<ErpAttention> util = new ExcelUtil<ErpAttention>(ErpAttention.class);
        return util.exportExcel(list, "提醒数据");
    }

    /**
     * 新增提醒
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存提醒
     */
    @RequiresPermissions("erp:attention:add")
    @Log(title = "提醒", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ErpAttention erpAttention)
    {
        return toAjax(erpAttentionService.insertErpAttention(erpAttention));
    }

    /**
     * 修改提醒
     */
    @GetMapping("/edit/{attentionId}")
    public String edit(@PathVariable("attentionId") Long attentionId, ModelMap mmap)
    {
        ErpAttention erpAttention = erpAttentionService.selectErpAttentionByAttentionId(attentionId);
        mmap.put("erpAttention", erpAttention);
        return prefix + "/edit";
    }

    /**
     * 修改保存提醒
     */
    @RequiresPermissions("erp:attention:edit")
    @Log(title = "提醒", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ErpAttention erpAttention)
    {
        return toAjax(erpAttentionService.updateErpAttention(erpAttention));
    }

    /**
     * 删除提醒
     */
    @RequiresPermissions("erp:attention:remove")
    @Log(title = "提醒", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(erpAttentionService.deleteErpAttentionByAttentionIds(ids));
    }
}
